/*Copyright (C) 2009 - 2011 MASSART GAUTHIER

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "../headers.h"

void balayage_horizontal_croix(void)
{
	int boucle1 = 0, boucle2 = 0, z = 40, x = 0, y[40] = {0}, b[40] = {0}, i = 0, init = 0;
	short jeu_couleur = 0;
	jeu_couleur = random(1, 3);

	while(init != 40) {
		b[init] = DEFAULT_SCREEN_SIZE_X - 1;
		init++;
	}

	CSLP_ColorText(COLOR_WHITE);

	while(boucle2 != DEFAULT_SCREEN_SIZE_X - 45) {
		boucle2++;

		CSLP_ColorText(COLOR_WHITE);

		while(boucle1 != boucle2) {

			if(boucle1 < 39) {
				z--;
				y[i]++;
				b[i]--;
				i++;
			}

			mvaddstr(x, y[i], "/");
			mvaddstr(x, b[i], "\\");
			mvaddstr(z, y[i], "/");
			mvaddstr(z, b[i], "\\");

			if(boucle1 < 39) {
				x++;
			}


			boucle1++;
		}

		x = 0, z = 40, i = 0;

		boucle1 = 0;
		refresh();
		CSLP_Sleep(5);
	}

	CSLP_Sleep(150);
}

void quitter(void) {
	curs_set(0);

	if(animations_bienvenue_fin) {
		do {
			CSLP_ColorText(COLOR_WHITE);
			clear();
			move(14, 0);
			addstr("\t\t\t                              \\\\\\|||||||///\n");
			addstr("\t\t\t                               \\\\");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("  ~ ~  ");
			CSLP_ColorText(COLOR_WHITE);
			addstr("//\n");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("\t\t\t                                (  ");
			CSLP_Color(COLOR_RED, COLOR_BLACK);
			addstr("@ @  ");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr(")\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("┌───────");
			CSLP_Color(COLOR_YELLOW, COLOR_WHITE);
			addstr("oOOo");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("─");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("(_)");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("─");
			CSLP_Color(COLOR_YELLOW, COLOR_WHITE);
			addstr("oOOo");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("────────┐\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("│                            │\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("│          ");
			CSLP_Color(COLOR_BLUE, COLOR_WHITE);
			addstr("A BIENTOT");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("         │\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("│                            │\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("└─────────────");
			CSLP_Color(COLOR_YELLOW, COLOR_WHITE);
			addstr("Oooo.");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("──────────┘\n");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("\t\t\t                          .oooO     (   )\n");
			addstr("\t\t\t                           (   )     ) /\n");
			addstr("\t\t\t                            \\ (     (_/\n");
			addstr("\t\t\t                             \\_)\n");
			refresh();
			CSLP_Sleep(300);

			if(volume_musique > 9) {
				volume_musique -= 10;
			}

			CSLP_ColorText(COLOR_WHITE);
			clear();
			move(14, 0);
			addstr("\t\t\t                              \\\\\\|||||||///\n");
			addstr("\t\t\t                               \\\\");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("  ~ ~  ");
			CSLP_ColorText(COLOR_WHITE);
			addstr("//\n");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("\t\t\t                                (  ");
			CSLP_ColorText(COLOR_BLUE);
			addstr("@ @  ");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr(")\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("┌───────");
			CSLP_Color(COLOR_YELLOW, COLOR_WHITE);
			addstr("oOOo");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("─");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("(_)");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("─");
			CSLP_Color(COLOR_YELLOW, COLOR_WHITE);
			addstr("oOOo");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("────────┐\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("│                            │\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("│          ");
			CSLP_Color(COLOR_RED, COLOR_WHITE);
			addstr("A BIENTOT");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("         │\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("│                            │\n");
			CSLP_Color(COLOR_BLACK, COLOR_BLACK);
			addstr("\t\t\t                      ");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("└─────────────");
			CSLP_Color(COLOR_YELLOW, COLOR_WHITE);
			addstr("Oooo.");
			CSLP_Color(COLOR_BLACK, COLOR_WHITE);
			addstr("──────────┘\n");
			CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
			addstr("\t\t\t                          .oooO     (   )\n");
			addstr("\t\t\t                           (   )     ) /\n");
			addstr("\t\t\t                            \\ (     (_/\n");
			addstr("\t\t\t                             \\_)\n");
			refresh();
			CSLP_Sleep(300);

			if(volume_musique > 4) {
				volume_musique -= 5;
			}
		}
		while(volume_musique > 5);

		balayage_horizontal_croix();

		CSLP_Sleep(100);
	}
	else {
		short x = 0, y = 0, caractere = 1;

		clear();

		while(y != 40) {
			while(x < DEFAULT_SCREEN_SIZE_X) {
				if(caractere == 1) {
					CSLP_Color(COLOR_BLACK, COLOR_BLACK);
					mvaddstr(y, x, "♠");
				}
				else if(caractere == 2) {
					CSLP_Color(COLOR_RED, COLOR_BLACK);
					mvaddstr(y, x, "♥");
				}
				else if(caractere == 3) {
					CSLP_Color(COLOR_GREEN, COLOR_BLACK);
					mvaddstr(y, x, "♣");
				}
				else if(caractere == 4) {
					CSLP_Color(COLOR_RED, COLOR_BLACK);
					mvaddstr(y, x, "♦");
				}
				else if(caractere == 5) {
					CSLP_Color(COLOR_YELLOW, COLOR_BLACK);
					mvaddstr(y, x, "☺");
					caractere = 0;
				}

				caractere = random(1, 5);
				x += 3;
			}

			y++;
			x = 0;
		}

		CSLP_ColorText(COLOR_BLUE);
		mvaddstr(19, x_begin_center(20), "┌──────────────────┐");
		mvaddstr(20, x_begin_center(20), "│");
		CSLP_ColorText(COLOR_WHITE);
		printw("     A BIENTOT    ");
		CSLP_ColorText(COLOR_BLUE);
		addstr("│");
		CSLP_ColorText(COLOR_BLUE);
		mvaddstr(21, x_begin_center(20), "└──────────────────┘");
		refresh();

		while(volume_musique > 2) {
			volume_musique -= 2;
			CSLP_Sleep(50);
		}
	}
	clear();
	refresh();
}
